/* 封装一个指令用以实现判断宽度是否小于768px, 增加、删除class */
class miniNavbar{
    constructor(){
        this.restrict = 'A';
    }

    link(scope, element, attrs, controller) {
        var mq = (query, callback, usePolyfill) => {
            var host = {};
            var isMatchMediaSupported = !!(window && window.matchMedia) && !usePolyfill;
            if(isMatchMediaSupported) {
                var res = window.matchMedia(query);
                callback.apply(host, [res.matches, res.media]);
                res.addListener( (changed) => {
                    callback.apply(host, [changed.matches, changed.media]);
                });
            }
        }

        mq('all and (max-width: 767px)', (match) => {
            if (match) {
                element.addClass('body-small')
            } else {
                element.removeClass('body-small')
            }
        });
    }
}

export default miniNavbar;